
*5) Country characteristics by BLA signing in the past 10 years

	*a) country characteristics

	use nat_BLA_data_1945_2020, clear

	tsset code year

	forval i = 1/10 {
	
		gen l`i'_bla_any = L`i'.bla_any
		
	}
	
	egen bla_any_past10 = rowmax(bla_any l?_bla_any l??_bla_any)
	
	gen pc_rgdpe = rgdpe/pop
	gen emp_rate = emp/pop
	gen trade_share = (imports_all+exports_all)/(pl_gdpo*cgdpo*1000000)
	
	*BLA signers
	cap mat drop sum_nat_bla1
	foreach var in pc_rgdpe pop emp_rate avh trade_share polity2 deaths_conflicts {
	
		qui sum `var' if bla_any_past10==1, d
		mat tempsum = [`r(mean)', `r(sd)', `r(p10)', `r(p90)']
		mat rownames tempsum = `var'
		mat sum_nat_bla1 = nullmat(sum_nat_bla1)\tempsum
		
	}
	
	*BLA non-signers
	cap mat drop sum_nat_bla0
	foreach var in pc_rgdpe pop emp_rate avh trade_share polity2 deaths_conflicts {
	
		qui sum `var' if bla_any_past10==0, d
		mat tempsum = [`r(mean)', `r(sd)', `r(p10)', `r(p90)']
		mat sum_nat_bla0 = nullmat(sum_nat_bla0)\tempsum
		
	}
	
	mat sum_nat = sum_nat_bla1,sum_nat_bla0
	
	*Count
	count if bla_any_past10==1
	scalar count_nat_bla1 = `r(N)'
	
	count if bla_any_past10==0
	scalar count_nat_bla0 = `r(N)'
	
	*Effect sizes
	gen bla_any_past10_rev = bla_any_past10 //replacing 0 with 2 so we get the right sign
	replace bla_any_past10_rev = 2 if bla_any_past10==0
	
	cap mat drop esizes_mat
	foreach var in pc_rgdpe pop emp_rate avh trade_share polity2 deaths_conflicts {
	
		esize twosample `var', by(bla_any_past10_rev)
		mat tempsum = [`r(d)', `r(lb_d)', `r(ub_d)']
		mat rownames tempsum = `var'
		mat esizes_mat = nullmat(esizes_mat)\tempsum
		
	}
	
	*b) dyad characteristics

	use dyad_BLA_data_1945_2020, clear

	tsset dyad_id year

	forval i = 1/10 {
	
		gen l`i'_bla_any = L`i'.bla_any
		
	}
	
	egen bla_any_past10 = rowmax(bla_any l?_bla_any l??_bla_any)
	
	gen pc_rgdpeA = rgdpeA/popA
	gen pc_rgdpeB = rgdpeB/popB
	gen pc_rgdpe_diff = abs(pc_rgdpeA-pc_rgdpeB)
	
	gen emp_rateA = empA/popA
	gen emp_rateB = empB/popB
	gen emp_rate_diff = abs(emp_rateA-emp_rateB)
	
	gen polity2_diff = abs(polity2A-polity2B)
	
	*Identifying "host"
	sort dyad_id year
	by dyad_id: gen gdpnonmiss = _n if !missing(pc_rgdpe_diff)
	by dyad_id: egen mingdpnonmiss = min(gdpnonmiss)
	
	gen first_host = codeA if pc_rgdpeA>pc_rgdpeB & !missing(pc_rgdpe_diff) & gdpnonmiss==mingdpnonmiss
	replace first_host = codeB if pc_rgdpeA<pc_rgdpeB & !missing(pc_rgdpe_diff) & gdpnonmiss==mingdpnonmiss
	
	by dyad_id: egen code_host = max(first_host)
	kountry code_host, from(cown) geo(men)
	gen MENA_host = GEO=="Middle East"
	drop GEO NAMES
	
	*GDP difference for MENA vs. non-MENA hosts
	gen pc_rgdpe_diff_MENA = pc_rgdpe_diff if MENA_host==1
	gen pc_rgdpe_diff_notMENA = pc_rgdpe_diff if MENA_host==0
	
	*GDP per capita ratio host to source
	gen pcgdp_ratio_host_source = ln(pc_rgdpeA)/ln(pc_rgdpeB) if codeA==code_host
	replace pcgdp_ratio_host_source = ln(pc_rgdpeB)/ln(pc_rgdpeA) if codeB==code_host
	
	*Higher Polity2 score in source
	gen higher_polity2_source = 0 if !missing(polity2A) & !missing(polity2B)
	replace higher_polity2_source = 1 if ((polity2A>polity2B & codeB==code_host) | (polity2A<polity2B & codeA==code_host)) & !missing(higher_polity2_source)
	
	*Treaty onset
	sort dyad_id year
	by dyad_id: gen onset = bla_past - bla_past[_n-1]
	replace onset = 0 if onset==.
	gen after_onset = onset==0 & bla_past==1
	
	*Time
	gen time = year-1945
	gen time_2 = time^2
	gen time_3 = time^3
	
	*Regressions to replicate Table 3 in Chilton/Posner
	#delimit ;
	
		local controls `"
		"c.pcgdp_ratio_host_source"
		"1.higher_polity2_source"
		"c.pcgdp_ratio_host_source 1.higher_polity2_source"
		"c.pcgdp_ratio_host_source 1.MENA_host 1.MENA_host#c.pcgdp_ratio_host_source"
		"1.higher_polity2_source 1.MENA_host 1.higher_polity2_source#1.MENA_host"
		"c.pcgdp_ratio_host_source 1.MENA_host 1.MENA_host#c.pcgdp_ratio_host_source
			1.higher_polity2_source 1.higher_polity2_source#1.MENA_host"
		"';
	
	#delimit cr
	
	local i = 1
	
	foreach c in `controls' {
	 
		di "`c'"
		qui logit onset `c' time time_2 time_3 if after_onset==0, vce(cl dyad_id)
		
		est store est`i++'
		
		
	}
	
	#delimit ;

	esttab est1 est2 est3 est4 est5 est6 using reg_chilton_posner, 
		keep(pcgdp_ratio_host_source 1.higher_polity2_source 1.MENA_host#c.pcgdp_ratio_host_source
		1.higher_polity2_source#1.MENA_host 1.MENA_host) 
		order(pcgdp_ratio_host_source 1.higher_polity2_source 1.MENA_host#c.pcgdp_ratio_host_source
		1.higher_polity2_source#1.MENA_host 1.MENA_host)
		coeflab(pcgdp_ratio_host_source "GDP per Capita Raio (host/source)" 1.higher_polity2_source
		"Higher Source Polity Score" 1.MENA_host#c.pcgdp_ratio_host_source "GDP per Capita Ratio \(\times\) Middle Eastern Host"
		1.higher_polity2_source#1.MENA_host "Higher Source Polity Score \(\times\) Middle Eastern Host" 1.MENA_host "Middle Eastern Host")
		b(3) se(3) booktabs label nolegend nonotes replace star(* 0.1 ** 0.05 *** 0.01)
		stats(r2_p N, labels("\(Pseudo-R^2\)" "\(N\)") fmt(3 0)) f nomtitles nonumbers 
		prehead("\begin{table}[!htbp]
		\fontsize{9}{10}\selectfont
		\caption{Treaty onset}
		\begin{tabularx}{\textwidth}{p{6cm}XXXXXX}
		\toprule
		& (1) & (2) & (3) & (4) & (5) & (6) \\")
		postfoot("\bottomrule 
		\addlinespace
		\multicolumn{7}{p{\textwidth}}{\fontsize{9}{10}\selectfont \textbf{Note}:}
		\end{tabularx}
		\end{table}");
			
	#delimit cr	
	
	
	*BLA signers
	cap mat drop sum_dyad_bla1
	foreach var in pc_rgdpe_diff pc_rgdpe_diff_MENA pc_rgdpe_diff_notMENA emp_rate_diff polity2_diff dist same_region{
	
		qui sum `var' if bla_any_past10==1, d
		mat tempsum = [`r(mean)', `r(sd)', `r(p10)', `r(p90)']
		mat rownames tempsum = `var'
		mat sum_dyad_bla1 = nullmat(sum_dyad_bla1)\tempsum
		
	}
	
	*BLA non-signers
	cap mat drop sum_dyad_bla0
	foreach var in pc_rgdpe_diff pc_rgdpe_diff_MENA pc_rgdpe_diff_notMENA emp_rate_diff polity2_diff dist same_region{
	
		qui sum `var' if bla_any_past10==0, d
		mat tempsum = [`r(mean)', `r(sd)', `r(p10)', `r(p90)']
		mat sum_dyad_bla0 = nullmat(sum_dyad_bla0)\tempsum
		
	}
	
	mat sum_dyad = sum_dyad_bla1,sum_dyad_bla0
	
	*Count
	count if bla_any_past10==1
	scalar count_dyad_bla1 = `r(N)'
	
	count if bla_any_past10==0
	scalar count_dyad_bla0 = `r(N)'
	
	*Effect sizes
	gen bla_any_past10_rev = bla_any_past10 //replacing 0 with 2 so we get the right sign
	replace bla_any_past10_rev = 2 if bla_any_past10==0
	
	foreach var in pc_rgdpe_diff pc_rgdpe_diff_MENA pc_rgdpe_diff_notMENA emp_rate_diff polity2_diff dist same_region {
	
		esize twosample `var', by(bla_any_past10_rev)
		mat tempsum = [`r(d)', `r(lb_d)', `r(ub_d)']
		mat rownames tempsum = `var'
		mat esizes_mat = nullmat(esizes_mat)\tempsum
		
	}
	
	*TeX tables
	
	local count_nat_bla1 = count_nat_bla1
	local count_nat_bla0 = count_nat_bla0
	local count_dyad_bla1 = count_dyad_bla1
	local count_dyad_bla0 = count_dyad_bla0

	#delimit;	
		
		esttab mat(sum_nat,fmt(%9.2g)) using sumstats_main , replace booktabs gaps f coeflab(pc_rgdpe "Real GDP per capita" pop "Population (millions)" emp_rate "Employment to population ratio" avh "Annual hours worked" trade_share "Trade to GDP ratio" polity2 "Polity2 score" deaths_conflicts "Deaths from armed conflicts") 
			nomtitles collabels("Mean" "SD" "\thead{10th \\pct}" "\thead{90th \\pct}" "Mean" "SD" "\thead{10th \\pct}" "\thead{90th \\pct}")
			substitute(".&" "&" ".\\" "\\" "  ." "  0.") 
			prehead("\begin{table}[!htbp]
			\fontsize{9}{10}\selectfont
			\caption{Country and dyad characteristics.}
			\label{t:sumstats}
			\begin{tabularx}{\textwidth}{p{7cm}XXXXXXXX}
			\toprule
			& \multicolumn{4}{l}{\textbf{\thead{Signed a BLA\\in the past 10 yrs.}}} 
			& \multicolumn{4}{l}{\textbf{\thead{Did not sign a BLA\\in the past 10 yrs.}}}\\
			 & (1) & (2) & (3) & (4) & (5) & (6) & (7) & (8) \\
			\addlinespace")
			posthead("\midrule \vspace{12mm}\\
			\multicolumn{9}{l}{\emph{Panel A: Country-level}}\\
			\addlinespace
			\addlinespace")
			prefoot("\midrule
			\addlinespace
			N & \multicolumn{4}{l}{`count_nat_bla1'} & \multicolumn{4}{l}{`count_nat_bla0'} \\");

		esttab mat(sum_dyad,fmt(%9.2g)) using sumstats_main
			, append booktabs gaps f coeflab(pc_rgdpe_diff "Difference in GDP per capita" 
			pc_rgdpe_diff_MENA "Difference in GDP per capita (ME host)"  pc_rgdpe_diff_notMENA "Difference in GDP per capita (non-ME host)"
			emp_rate_diff "Difference in emp/pop ratios" polity2_diff "Difference in Polity2 scores" dist 
			"Distance between population centers" same_region "Same region") 
			nomtitles collabels(none) substitute(".&" "&" ".\\" "\\" "  ." "  0.")
			posthead("\midrule \vspace{12mm}\\
			\multicolumn{9}{l}{\emph{Panel B: Dyad-level}}\\
			\addlinespace
			\addlinespace")
			postfoot("\midrule
			\addlinespace
			N & \multicolumn{4}{l}{`count_dyad_bla1'} & \multicolumn{4}{l}{`count_dyad_bla0'} \\
			\bottomrule 
			\addlinespace
			\multicolumn{9}{p{\textwidth}}{\fontsize{9}{10}\selectfont Panel A presents country-level
			characteristics and Panel B dyad-level characteristics. Columns (1)-(4) summarize the listed
			variables for countries or dyads which signed at least 1 BLA within the past 10 years and 
			columns (5)-(8) for those without a BLA in the past 10 years.}
			\end{tabularx}
			\end{table}");
				
	#delimit cr	
